﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PB__Decoder_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
		}

        [Obsolete]
        private void button1_Click(object sender, EventArgs e)
        {

			var BytesIn = HexStrToByteArray(RichTextBox1.Text.Replace(" ", ""));
			if (BytesIn !=null)
            {
				ProtoBuff.TreeNodeStruct NodeStruct = new ProtoBuff.TreeNodeStruct();
				NodeStruct.NodeList = new List<TreeNode>();
				NodeStruct.parentNode = new TreeNode("Proto");
				NodeStruct.NodeList.Add(NodeStruct.parentNode);
				TreeView1.Nodes.Clear();
				NodeStruct = ProtoBuff.QuickDecodeProto(BytesIn, "", NodeStruct);
				TreeView1.Nodes.AddRange(NodeStruct.NodeList.ToArray());
				TreeView1.ExpandAll();
			}			
		}
				public byte[] HexStrToByteArray(string str)
		{
			try
			{
				Dictionary<string, byte> hexindex = new Dictionary<string, byte>();
				for (int i = 0; i <= 255; i++)
				{
					hexindex.Add(i.ToString("X2"), (byte)i);
				}
				if (str.Length % 2 == 1)
				{
					str = "0" + str;
				}
				List<byte> hexres = new List<byte>();
				for (int i = 0; i < str.Length; i += 2)
				{
					hexres.Add(hexindex[str.Substring(i, 2)]);
				}
				return hexres.ToArray();
			}
			catch (Exception ex)
			{

			}
			return null;
		}

        private void Form1_Load(object sender, EventArgs e)
        {
			RichTextBox1.Text = "080012001A340886BDA281061086BDA2810618DE8DA980032082D7E1BA0C288ACA8DD1034881B7A8EA0B58B89ECE890A60516886BDA28106700020022ACE060884BDA281061086AFEF11180122BC060A280886AFEF1110D8EDAEF90C18A601200B2891043085BDA2810638FCF9CDBD8580808001B801EBF301120808011000180020001A85060A82060A2708001085BDA2810618FCF9CDBD052000280C300038860140224A0CE5BEAEE8BDAFE99B85E9BB9112100A0E0A0CE6B688E681AFE6B58BE8AF9512C30422C0040A1B2952555231354F2425435F565F6040527D4E355B3125302E67696610B3A5241A352F33373437363233302D313230353039363834342D3341413336464334353546443042323533444538393038323333353246313035227316203131353130313034314442202020203539343631316533414133364643343535464430423235334445383930383233333532463130352E676966762F33373437363233302D313230353039363834342D33414133364643343535464430423235334445383930383233333532463130354128D00F3A103AA36FC455FD0B253DE890823352F105409A04489C0452352F33373437363233302D313230353039363834342D33414133364643343535464430423235334445383930383233333532463130355A041100000062552F6F66667069635F6E65772F33373437363233302F2F33373437363233302D313230353039363834342D33414133364643343535464430423235334445383930383233333532463130352F3139383F7465726D3D327A532F6F66667069635F6E65772F33373437363233302F2F33373437363233302D313230353039363834342D33414133364643343535464430423235334445383930383233333532463130352F303F7465726D3D32A801C601B001C501D201552F6F66667069635F6E65772F33373437363233302F2F33373437363233302D313230353039363834342D33414133364643343535464430423235334445383930383233333532463130352F3430303F7465726D3D32D8018003E001FE02EA01040802420012080A060A04F09F98B3124A32481006180122109459ED1C82537B0CA08172F7CF1210AC2897A60C30033A106130373138643466346237343263626350C80158C8016A120A0608AC0210AC020A0608C80110C8014001120C0A0A0A055BE590835D22010112044A0208001215AA02129A010FC80100F00100F80100900200CA04003001380042004800";
		}
	}


}
